﻿using System;

using DDDSample.Common.Validate;

namespace DDDSample.Domain.Model.Carrier
{
	/// <summary>
	/// Identifies a particular carrier movement, such as a flight number.
	/// </summary>
	public sealed class CarrierMovementId : ValueObject<CarrierMovementId>
	{
		private string id;

		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="id">Id string.</param>
		public CarrierMovementId(string id)
		{
			Validate.NotNull(id);
			this.id = id;
		}

		/// <summary>
		/// String representation of this carrier movement id.
		/// </summary>
		public string IdString
		{
			get { return this.id; }
		}

		public override bool SameValueAs(CarrierMovementId other)
		{
			return other != null && this.id.Equals(other.id);
		}

		public override bool Equals(object obj)
		{
			if (this == obj) return true;
			if (obj == null || GetType() != obj.GetType()) return false;

			CarrierMovementId other = (CarrierMovementId)obj;

			return SameValueAs(other);
		}

		public override int GetHashCode()
		{
			return this.id.GetHashCode();
		}

		public override string ToString()
		{
			return this.id;
		}

		private CarrierMovementId()
		{
			// Needed by hibernate
		}
	}
}
